home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48hor2
/
cmat.doc
< prev
next >
Wrap
Text File
|
1995-03-31
|
4KB
|
114 lines
Resp: 2 of 2 by wes at kuhub.cc.ukans.edu
Author: [Wes Hubert]
Date: Thu Apr 04 1991 22:56
Lines: 238
CMAT is an HP48 program for performing operations on columns of a
matrix. CMAT iterates over each row of the matrix, treating the n
columns of the matrix as if they were variables named C1, C2, ...
Cn, or, optionally, as if they were named with user-specified
names. The operations can be be limited to selected rows of the
matrix by supplying a boolean condition that must be met before
the computation is peformed. If the result column is not in the
original matrix, the matrix will be expanded to include the new
column.
Before executing CMAT, you must place on level two of the stack
the matrix object to process, and on level one of the stack either
an algebraic object that specifies the compuation to perform or a
list that specifies a series of variable names, conditions, and
computations.
For example, place the matrix
[[ 1 5 ]
[ 2 4 ]
[ 3 6 ]]
on the stack.
Next place the algebraic object
'C4=C2^2+C1'
on the stack. It specifies computing a new column, column four, as
column two squared plus column one. Since column three is not part
of the original matrix, it is filled with zeros.
Executing CMAT will replace these objects with the matrix:
[[ 1 5 0 26 ]
[ 2 4 0 18 ]
[ 3 6 0 39 ]]
The Evaluation List
For computations to complex to specify with a single equation, CMAT
allows an evaluation list instead of an equation. The list can contain
name assignment lists and conditional expression lists as well as
equations. Each list begins with a string. "Names", "If', or "Compute".
The first character is sufficient (e.g. "N" for "Names). A name list
consists of one or more lists whose first item is a column number and
whose second item is a name for the column. A conditional list contains
and algebraic object specifying a condition that must be true for a row
in order for the following equation to be processed. An imperative
list contains an equation, and is equivalent to an equation by itself
not contained in a list (e.g. {"C" 'equation'} and 'equation' are
treated identically.
Name List {"Names" {2 'Age'} {3 'Income'}}
Conditional {"If" 'boolean' 'equation'}
Imperative {"Compute" 'equation'}
If a column is not explicitly named, it has a default of of Cn where
'n' is the column number, but 'Cn' cannot be used to specify a column
that has been named. It must be called by its name.
An example list:
{ { "N" {4 'Sum'} {5 Mean'}}
'Sum=C1+C2+C3'
{ "If" 'C1>0' 'Mean=Sum/3' } }
Immediate Execution Functions
Functions that are available only for immediate execution from the
keyboard can be placed into programs by saving them in a program.
For example, RAND cannot be used directly in an algebraic
expression, but
<< RAND >> 'RANDOM' STO
creates a random number function that can then be used in an
algebraic expression such as
'C1=TRNC(10*RANDOM,0)'
to create a column of random numbers in the range 0 through 9.
Missing Value Indicators
To handle missing data, filter column variables with functions
such VALID and VALUE in the example below. In this example,
negative values indicate invalid data. The function VALID returns
1 if its argument is in the valid data range, 0 otherwise. The
function VALUE returns the original data value if it is in the
valid data range, 0 otherwise. Using these functions, C4 counts
the number of valid data points, C5 the total of valid data
values, and C6 the mean of the valid data.
<< << n | IF 'n>-1' THEN 1 ELSE 0 END >> >> 'VALID' STO
<< << n | IF 'n>-1' THEN n ELSE 0 END >> >> 'VALUE' STO
{ 'C4=VALID(C1)+VALID(C2)+VALID(C3)'
'C5=VALUE(C1)+VALUE(C2)+VALUE(C3)'
{"IF" 'C4>0' 'C6=C5/C4'} }
The condition 'C4>0'prevents dividing by zero when evaluating the
expression for C6 if there are no valid values in a row.